import axios from '@/libs/api.request'
import Vue from 'vue'
/*
 管理端登录接口
 */
export const login = ({ userName, password, url, code }) => {
  let authApiPhp = Vue.prototype.$config.authApiPhp
  let data = JSON.stringify({
    username: userName,
    password: password,
    code: code
  })
  if (url === '' && url === undefined && url === null) {
    url = '/api/uc/sc/loginService/userLogin_encrypt' // 密文密码登录接口
    // url = '/api/uc/sc/loginService/userLogin'
  }
  if (authApiPhp) {
    url = '/wl/sys/userLogin/'
    data = {
      username: userName,
      password: password,
      code: code
    }
  }
  return axios.request({
    url: url,
    data: data,
    type: 'post',
    php: authApiPhp
  })
}

export const userLogOut = () => {
  return axios.request({
    url: '/api/ac/sc/loginService/userLogOut',
    type: 'get'
  })
}

export const getUserInfo = () => {
  let authApiPhp = Vue.prototype.$config.authApiPhp
  let javaUserOldApi = !!Vue.prototype.$config.javaUserOldApi
  let url = authApiPhp ? '/wl/sys/info' : javaUserOldApi ? '/api/as/info' : 'api/ac/sc/systemUserService/info'
  return axios.request({
    url: url,
    type: 'get'
  })
}
/**
 * 获取一级菜单java
 * @returns {*|Promise|Promise<any>}
 */
export const userMenuList = () => {
  let authApiPhp = Vue.prototype.$config.authApiPhp
  let url = authApiPhp ? '/wl/sys/userMenuList' : '/api/as/sc/menu/userMenuList'
  return axios.request({
    url: url,
    type: 'get'
  })
}
/**
 * 获取一级下的所有菜单
 * @param menu_id
 * @returns {*|Promise|Promise<any>}
 */
export const newMenulist = (menu_id) => {
  let authApiPhp = Vue.prototype.$config.authApiPhp
  let url = authApiPhp ? '/wl/sys/getMenuList' : '/api/as/sc/menu/getMenu2List'
  return axios.request({
    url: url,
    data: { parent_ids: menu_id },
    type: 'get'
  })
}

export const getPhpMenus = () => {
  return axios.request({
    url: '/wl/menus',
    type: 'get',
    php: true
  })
}

/**
 * 获取验证码
 */
export const getCodeImg = (url) => {
  if (!url) {
    url = '/api/uc/sc/loginService/genVerifyCode'
  }
  return axios.request({
    url,
    type: 'post'
  })
}

/**
 * 获取手机登录的二维码
 * @returns {Promise<unknown>|*}
 */
export const getLoginQrcode = () => {
  return axios.request({
    url: '/api/ac/sc/loginService/getLoginQrcode',
    type: 'get'
  })
}

export const qrcodeLogin = (data) => {
  return axios.request({
    url: '/api/ac/sc/loginService/qrcodeLogin',
    type: 'post',
    data: data,
    await: true
  })
}

/**
 * 获取登录方式
 */
export const getLoginType = () => {
  return axios.request({
    url: '/api/ac/sc/loginService/phoneAndEmailexists',
    type: 'post'
  })
}
